function loadAnimation(complete){
    if(!complete){
        jQuery('#lightBox').html('<img src="style/img/loading.gif"/>');
        jQuery('#lightBox').show('fast');
    } else{
        jQuery('#lightBox').html('');
        jQuery('#lightBox').hide('fast');
    }
                
}
function login(){
    loadAnimation(false);
    jQuery.ajax({
        url: 'control/generalControl.php',
        data: 'flag=login&username='+jQuery('#username').val()+'&password='+jQuery('#password').val(),
        type: 'post',
        success: function(data){
            if(data === 'true'){
                window.location = '?flag=goToPage&pageName=home';
            } else{
                loadAnimation(true);
                alert("E-mail e/ou senha inválidos.");
            }
        }
    });
}
function askLogout(){
    var conf = confirm("Sair?");
    if(conf){
        logout();
    }
}
function logout(){
    loadAnimation(false);
    jQuery.ajax({
        url: 'control/generalControl.php',
        data: 'flag=logout',
        type: 'post',
        success: function(){
            window.location = ROOT_ADDRESS;
        }
    });
}
function ajaxSqlQuery(query, handler){
    jQuery.ajax({
        url:'control/generalControl.php',
        data:'flag=mysqlQuery&query='+query,
        type:'post',
        datatype:'json',
        success:function(data){
            handler(jQuery.parseJSON(data));
        }
    });
}
jQuery('#lightBox').hide();